/**
 * 道具配置表
 */
export enum PropType {
  /**切换下一个水果 */
  ChangeFruit = 1,
  /**消除一个水果 */
  DelOneRuit = 2,
}

/**
 * 道具类
 */
export class PropInfo {
  /**道具ID */
  public id: number = 0;

  /**道具名字 */
  public name: string = "";

  /**道具描述 */
  public desc: string = "";

  /**特殊属性值 */
  public attrValue: Array<number> = [];

  /**道具类型 */
  public ptype: number;

  /**道具资源 */
  public prefab: string = "";

  /**使用说明 */
  public useDesc: string = "";

  /**icon */
  public icon: string = "";

  /**propType */
  public propType: number = 0;
}

export default class PropConfig {
  private static _propCfg = [
    { "id": 1, propType: 1, ptype: 1, useDesc: "", icon: "", prefab: "1", "name": "交换", "attrValue":[10], "desc": "更换下一个水果的种类" },
    { "id": 2, propType: 2, ptype: 1, useDesc: "", icon: "", prefab: "1", "name": "锤子", "attrValue":[0], "desc": "消除指定的一个水果" },
  ];

  public static initCfg(cfg: any) {
    this._propCfg = cfg;
  }

  public static getProp(id: number): PropInfo {
    for (const cfg of this._propCfg) {
      if (cfg.id == id) {
        return cfg;
      }
    }
    return null;
  }

  public static getPropCfg(): any {
    return this._propCfg;
  }

  public static getPropListByType(propType: PropType): Array<PropInfo> {
    let list: Array<PropInfo> = [];
    for (const id in this._propCfg) {
      let prop: PropInfo = this._propCfg[id];
      if (prop.ptype == propType) {
        list.push(prop);
      }
    }
    return list;
  }
}
